<?php
/**
 * Created by PhpStorm.
 * User: leo
 * Date: 2018/5/16
 * Time: 21:31
 */
header('Content-Type:application/json');
include '../classes/logincheck.php';
include '../classes/conn.php';
$id=$_POST['id'];
if(islogin()!='teacher_login') {
    die('error');
}

//查询作业所属班级
$query1="select class from homework where Id='{$id}'";
$res=mysql_query($query1);
$row=mysql_fetch_assoc($res);
$class=$row['class'];


//查询已经交了作业的学生
$already=array();
$query2="select * from submit where homework='{$id}'";
$res=mysql_query($query2);
while ($row=mysql_fetch_assoc($res)){
    $already[]=$row;
}

//查询所有学生
$all=array();
$query3="select num,name from student where class='{$class}'";
$res=mysql_query($query3);
while ($row=mysql_fetch_assoc($res)){
    $all[]=$row;
}

//将name加入$already
for($i=0;$i<count($all);$i++){
    for($j=0;$j<count($already);$j++){
        if($all[$i]['num']==$already[$j]['student']){
            $already[$j]['name']=$all[$i]['name'];
        }
    }
}

$nosub=array();
//查询未交作业的学生
if(count($already)){
    $query4="select num,name from student where class='{$class}' and num not in (select student from submit where homework='{$id}')";
    $res=mysql_query($query4);
    while ($row=mysql_fetch_assoc($res)){
        $nosub[]=$row;
    }
}

$data=array('already'=>$already,'nosub'=>$nosub,'all'=>$all);
$data=json_encode($data);
echo $data;